local excel = load_excel('装备设置.xlsx','专属')
for i,data in ipairs(excel) do
    local name = data['装备序号']
    local tip = ('%s'):format(atts_tip(data))
    data.state = table_sx(data)
    data.index = i

    local tip = tip:gsub('([%d]+[%d%.]?[%d]-)([\0%%]?)',function(num,ex)
        return ('|cff00ff00%s%s|r'):format(num,ex)
    end)

    data.base_tip = ('|cffeacb40武器属性：|r|n%s'):format(tip)
    data.attr_tip = ''
    data.gold = data['强化价格']
    data.odds = data['强化成功率'] * 100
    if i==#data then
        data.tip = [['base_tip'|n'abi_tip'|n'attr_tip']]
    else
        data.tip = [[|cff999999强化概率:|r|cff00ff00'odds'%|r|n|n'base_tip'|n'abi_tip'|n'attr_tip'|n'jx_tip']]
    end
    data.jx_tip = function(self)
        local player = ac.player.self
        local count = player:get_data('武器觉醒')
        if count==nil then
            if self.index<50 then
                return ''
            end
            return '|cffff0000摧毁魔域城堡觉醒|r'
        end
        return ('【武器觉醒】|n每击杀1000敌人获得全属性加成+1%%|n累计获得：全属性+%s%%'):format(count)
    end

    data.name = name

    ac.lni('skill',name,data)
end


ac.skill('专属被动'){
    model1 = [[WQTE_hyd.mdl]],
    temp = '攻击触发',
    odds = 15,
    cool = 4,
    tip = [[|n|cffeacb40魔法火球：|r|n◆攻击|cff00ff0015%|r概率对|cff00ff005|r个目标释放火焰弹，造成|cffff6800攻击力*150%|r的|cffffff00自适应伤害|r|n]],
    on_run = function(self,hero,target)
        local damage = hero:get('攻击') * 1.5
        local group = ac.selector('unit'):range(hero,hero:get('攻击距离')+200):enemy(hero):get(5)
        for _,unit in ipairs(group) do
            hero:launch_missile(unit,self.model1,1200,0.15,function(mvr)
                hero:create_damage(unit, damage)
            end)
        end
    end,
}

ac.game:event '玩家-武器觉醒'(function(_,player)
    local hero = player.hero
    player:set_data('武器觉醒',0)
    if hero then
        local count = 0
        hero:event '英雄-击杀单位'(function()
            count = count + 1
            if count>=1000 then
                count = 0
                hero:add('全属性加成',1)
                player:set_data('武器觉醒',player:get_data('武器觉醒',0) + 1)
            end
        end)
    end
end)

ac.game:event '玩家-设置专属'(function(_,player,data)
    local hero = player.hero
    if data and hero then
        local temp = hero:get_data('专属被动')
        local ex = hero:get_data('特殊词条')
        local old = hero:get_data('专属数据')
        local new = hero:add_skill(data.name)
        if old then
            old:remove()
        end
        new.attr_tip = ex
        new.abi_tip = temp.tip
        new:gc(ac.loop(1000,function()
            local gold = new['强化价格'] or 0
            new.show_effect = player:get('金币')>=gold
        end))
        load_item_state(hero,old,-1)
        load_item_state(hero,new,1)

        hero:set_data('专属数据',new)
        player:set_data('专属等级',new.index)
        player:notify('玩家-更新专属',player,new)
    end
end)

ac.sync:event '同步-升级专属'(function(_,player)
    local hero = player.hero
    local skill = hero and hero:get_data('专属数据')
    local data = skill and excel[skill.index + 1]
    if data then
    --if data and (data.index<=50 or player:get_data('武器觉醒')) then
        local gold = skill['强化价格']
        if player:get('金币')<gold then
            show_panel_effect(player,ac['专属UI'],'金币')
            return
        end
        player:add('金币',-gold)
        if math.random(100)>data.odds then
            show_panel_effect(player,ac['专属UI'],'失败')
            return
        end
        show_panel_effect(player,ac['专属UI'],'刷新')
        player:notify('玩家-设置专属',player,data)
    end
end)



ac.game:event '玩家-选择英雄完毕'(function(_,player,hero)
    local temp = hero:add_skill('专属被动')
    hero:set_data('专属被动',temp)
    player:notify('玩家-设置专属',player,excel[1])
end)